#ifndef BLOCK_OPERATIONS_H_
#define BLOCK_OPERATIONS_H_

#include <unistd.h>

// Writes |size| bytes from |buf| at |at| in |fd|.  The descriptor is
// seeked. Save the position with ftell before calling if you want to
// preserve it.
// 
// |block_size| specifies, in bytes, the size of a block.  This value
// should NOT be changed between calls to this function.
//
// This function writes at a block granularity, and will only write one
// block at a time.  It returns the offset of the last byte modified.
//
// To calculate the number of bytes written, take the return value, and
// subtract it from the |at| that was passed in.
//
// This function returns a negative value that is a negated errno on error.
off_t update_block(size_t block_size, int fd, off_t at, const char* buf,
                   size_t size);

#endif  // BLOCK_OPERATIONS_H_
